package v9.assist.analyst

import android.graphics.Bitmap
import kotlinx.coroutines.script.Block
import kotlinx.coroutines.script.TARGET
import kotlinx.coroutines.script.analysis.Analysis
import kotlinx.coroutines.script.SMapBase.hitBox
import kotlinx.coroutines.script.SMapBase.hitDeathRed
import kotlinx.coroutines.script.SMapBase.hitEquipO
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyBlue
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyYellow
import kotlinx.coroutines.script.SMapBase.hitTeammate
import kotlinx.coroutines.script.tes.ColorDiffer
import kotlinx.coroutines.script.tes.printLog
import kotlinx.coroutines.script.tes.pt
import kotlinx.coroutines.script.tes.rgb
import kotlinx.coroutines.script.tes.shake
import v9.assist.script.sLastFeature30Ts
import v9.assist.script.xBossBesideTs
import v9.assist.script.xLastAtkTs
import v9.assist.script.xLastAtvTs
import v9.assist.script.xLastPetBlacksmithTs
import v9.assist.script.xLastSceneEnterTs
import v9.assist.script.xLastUnknownTs
import kotlin.math.abs

private val hitRoad by lazy {
    val out = mutableSetOf<ColorDiffer>()
    out.addAll(setOf(0xff464439.toInt().rgb(6),)) // 主路径
    out.addAll(setOf(0xff36372d.toInt().rgb(24),)) // p1
    out.addAll(setOf(0xff363128.toInt().rgb(24),)) // p2
    out.addAll(hitEquipO)
    out.addAll(hitBox)
    out.addAll(hitDeathRed)
    out.addAll(hitTeammate)
    out.addAll(hitSMapEnemyYellow)
    out.addAll(hitSMapEnemyBlue)
    out
}

var anaLastSMapFWFeature1Ts = 0L // Boss祭坛右侧
var anaLastSMapFWFeature3Ts = 0L // P1无敌人
var anaLastSMapFWFeature4Ts = 0L // P2Boss击破卡右下.
var anaLastSMapFWFeature5Ts = 0L // 最终地点前的台阶死角
var anaLastSMapFWFeature6Ts = 0L // 最终地点前的台阶黑墙
var anaLastSMapFWFeature7Ts = 0L // 直通特征
var anaLastSMapFWFeature8Ts = 0L // 第一场景顶端
var anaLastSMapFWFeature9Ts = 0L // 副本起点
var anaLastSMapFWFeature10Ts =0L // 黑墙后的柱子
var anaLastSMapFWFeature11Ts = 0L // 已经通关.卡离场小角落

var anaLastToEliteEnemyTs = 0L // 这个是过门的时候的强制互动逻辑比如P1、P2Boss击破后的特征门

fun rasterizeMapFW(ss: Bitmap): Array<IntArray> {
    return rasterizeMap(ss, hitRoad)
}

fun analysisMapFW(ss: Bitmap) {
    //printLog { "analysisMapFW" }

    analysisMapElements(ss)
    val returnMapArray = rasterizeMapFW(ss)

    if (blockEliteEnemyBoss != null && mapEnemyList.isNotEmpty()) {
        // 优先Boss
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to boss" }
        lastSMapTargetToBossTs = System.currentTimeMillis()
        if (mapElementDistance(blockEliteEnemyBoss) < 30.pt) xBossBesideTs = System.currentTimeMillis()
    } else if (mapEnemyList.isNotEmpty()
        && System.currentTimeMillis() - anaLastPageSceneEnterTs > 10000 // 刚开局就需要
        && System.currentTimeMillis() - anaLastSceneSettleTs > 20000
        && !bsSceneSettle && !bsSceneSettleBlacksmith) {
        // 优先敌人
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to elite enemy" }
        anaLastToEliteEnemyTs = System.currentTimeMillis()
    } else if (bsSceneSettleBlacksmith && mapBlacksmithList.isNotEmpty()) {
        mapTargetList.add(mapBlacksmithList.random())
        printLog { "analyst target to blacksmith" }
    } else if (bsSceneSettle && mapBlueDoorList.isNotEmpty()) {
        mapTargetList.add(mapBlueDoorList.random())
        printLog { "analyst target to blueDoor" }
//    } else if (mapRightNotArrived.size > 0 && System.currentTimeMillis() - lastBlueDoorTs < 3000) {
//        mapTargetList.add(mapRightNotArrived.random())
//        printLog { "analyst target to right" } // 最后一关会翻车
    } else if (mapTopNotArrived.size > 0) {
        mapTargetList.add(mapTopNotArrived.random())
        printLog { "analyst target to top" }
    } else if (mapLeftNotArrived.size > 0  && mapLeftNotArrived.map { it.second }.average() < smallMap.height * 0.75f) {
        mapTargetList.add(mapLeftNotArrived.random())
        printLog { "analyst target to left" }
    } else if (System.currentTimeMillis()- lastEliteEnemyBossTs < 10000) { // 秒差不多刚好
        mapSampleArrived
            .filter { it.second < selfInSmallMap.y - smallMap.top }
            .minByOrNull { it.second }?.also {
                mapTargetList.add(it)
                printLog { "analyst target to sample top " }
            }
    } else if (mapSampleArrived.size > 0) {
        mapSampleArrived.maxByOrNull { it.first }?.also {
            mapTargetList.add(it)
            printLog { "analyst target to sample" }
        }
    }

    if (mapTargetList.isNotEmpty()) {
        val target = mapTargetList.random()
        returnMapArray[target.first][target.second] = TARGET
    }

    angleByRoad = analysisRasterizeMap(returnMapArray)
    angleByRoad = angleSpecialAdjust(angleByRoad ?: 42.shake(5))

    // map feature
    analysisMapFWIsStartPoint(ss)

    if ((blockBlueDoor == null || blockBlacksmith == null)
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000) {
        printLog { "analystFW $mapSimpleStatus" }

        if (System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapBottomP ?: -1f) in 0.46 .. 0.60
            && lastMapLeftP == null
            && lastMapRightP == null
            && !bsSceneSettle && !bsSceneSettleBlacksmith
            && System.currentTimeMillis() - lastEliteEnemyTs > 3000
            && System.currentTimeMillis() - lastBlueDoorTs > 3000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000 //第一阶段也会误触发
        ) {
            // [上,0s,0.3079096,c:1][下,0s,0.5378684,c:37][左,34s,c:0][右,40s,c:0]][Road,c:37]
            // [上,7s,c:0][下,0s,0.5388237,c:39][左,1737284896s,c:0][右,1737284896s,c:0]][Road,c:37]
            // [上,0s,0.3079096,c:1][下,0s,0.5378684,c:37][左,1737284687s,c:0][右,1737284687s,c:0]][Road,c:38]
            printLog { "analystFW 节点.Boss祭坛右侧" }
            anaLastSMapFWFeature1Ts = System.currentTimeMillis()

        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.26 .. 0.36
            && (lastMapBottomP ?: -1f) in 0.31 .. 0.41
            && (lastMapLeftP ?: -1f) in 0.58 .. 0.68
            && lastMapRightP == null
            && lastMapRoadC in 52 .. 64
            && System.currentTimeMillis() - xLastAtkTs > 20000
            && System.currentTimeMillis() - xLastAtvTs > 20000
            && System.currentTimeMillis() - lastBlueDoorTs > 10000
        ) {
            // analystFW [上,0s,0.31790525,c:26][下,0s,0.3681144,c:64][左,0s,0.63076925,c:40][右,9s,c:0]][Road,c:58]
            printLog { "analystFW 节点.无敌人P1" }
            anaLastSMapFWFeature3Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.10 .. 0.20
            && (lastMapLeftP ?: -1f) in 0.82 .. 0.94
            && lastMapRightP == null
            && lastMapRoadC in 12 .. 28
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 3000
        ) {
            // [上,47s,c:0][下,0s,0.15375303,c:42][左,0s,0.888604,c:15][右,50s,c:0]][Road,c:21]
            printLog { "analystFW 节点.P2Boss击破卡右下" }
            anaLastSMapFWFeature4Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.01 .. 0.12
            && (lastMapBottomP ?: -1f) in 0.46 .. 0.66
            && (lastMapLeftP ?: -1f) in 0.20 .. 0.38
        ) {
            // [上,0s,0.036723163,c:10][下,0s,0.56340235,c:54][左,0s,0.30341882,c:60][右,0s,0.97863245,c:2]][Road,c:48]
            // [上,0s,0.037853107,c:10][下,0s,0.59450436,c:44][左,0s,0.2906733,c:57][右,2s,c:0]][Road,c:47]
            // 反  [上,0s,0.059322033,c:1][下,0s,0.53264284,c:36][左,0s,0.26505664,c:43][右,9s,c:0]][Road,c:40]
            printLog { "analystFW 节点.最终地点前的台阶死角" }
            anaLastSMapFWFeature5Ts = System.currentTimeMillis()
        }  else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.02 .. 0.22
            && (lastMapLeftP ?: -1f) in 0.13 .. 0.27
            && (lastMapRightP ?: -1f) in 0.80 .. 0.94
        ) {
            // [上,0s,0.11671127,c:38][下,0s,0.9491525,c:4][左,0s,0.2052437,c:37][右,0s,0.87606835,c:26]][Road,c:51]
            // [上,0s,0.11671127,c:38][下,0s,0.9557439,c:3][左,0s,0.1986569,c:35][右,0s,0.8716366,c:27]][Road,c:51]
            printLog { "analystFW 节点.最终地点前的台阶黑墙" }
            anaLastSMapFWFeature6Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.64 .. 0.76
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.22 .. 0.32
            && System.currentTimeMillis() - xLastAtkTs > 4000
            && System.currentTimeMillis() - lastBlueDoorTs < 2000
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000
        ) {
            printLog { "analystFW 节点.直通" }
            // 下不要了
            // [上,0s,0.7103618,c:94][下,0s,0.43220338,c:1][左,138s,c:0][右,0s,0.2757667,c:51]][Road,c:56]
            // [上,0s,0.69797075,c:98][下,0s,0.4378531,c:2][左,78s,c:0][右,0s,0.28315923,c:54]][Road,c:56]
            anaLastSMapFWFeature7Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
           // 这个可能会卡在2秒内吧. && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
//            && 不考虑上面避免队友干扰  (lastMapTopP ?: -1f) in 0.14 .. 0.28
            && lastMapBottomP == null
            && (lastMapLeftP ?: -1f) in 0.12 .. 0.21
            && (lastMapRightP ?: -1f) in 0.61 .. 0.81
            && System.currentTimeMillis() - xLastAtkTs > 3000
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000 // 开局触发了这个?
        ) {
            printLog { "analystFW 节点.黑墙后的柱子" }
            // [上,0s,0.2089807,c:48][下,1s,c:0][左,0s,0.17058405,c:12][右,0s,0.67948717,c:25]][Road,c:61]
            //不考虑上面避免队友干扰
            // [上,0s,0.2089807,c:48][下,3s,c:0][左,0s,0.17784351,c:13][右,0s,0.67001116,c:23]][Road,c:57]
            // [上,0s,0.157572,c:41][下,31s,c:0][左,0s,0.1826923,c:20][右,0s,0.7841089,c:27]][Road,c:60]
            // [上,0s,0.24216239,c:51][下,47s,c:0][左,0s,0.16140696,c:13][右,0s,0.650641,c:20]][Road,c:60]
            // [上,0s,0.18806347,c:47][下,30s,c:0][左,0s,0.16962524,c:13][右,0s,0.67602766,c:21]][Road,c:61]
            // [上,0s,0.1846598,c:46][下,16s,c:0][左,0s,0.17058405,c:12][右,0s,0.67948717,c:25]][Road,c:61]
            anaLastSMapFWFeature10Ts = System.currentTimeMillis()
        }

        //
    }

    if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
        && lastMapTopP == null
        && (lastMapBottomP ?: -1f) in 0.48 .. 0.60
        && lastMapLeftP == null
        && lastMapRightP == null
        && System.currentTimeMillis() - lastBlueDoorTs < 3000 // 已经通关了
    ) {
        // [上,14s,c:0][下,0s,0.5469291,c:31][左,15s,c:0][右,16s,c:0]][Road,c:40]
        printLog { "analystFW 节点.Boss祭坛右侧[已通关]" }
        anaLastSMapFWFeature11Ts = System.currentTimeMillis()
    }



    if (System.currentTimeMillis() - anaLastPageSceneEnterTs > 8000
        && System.currentTimeMillis() - xLastUnknownTs > 8000
        && System.currentTimeMillis() - anaLastHasEnemyNameTs > 4000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 4000
        && blockBlueDoor != null
        && blockBlacksmith != null
        && !bsSceneSettle && !bsSceneSettleBlacksmith
        && simpleAssertSceneCompleted(blockBlueDoor, blockBlacksmith)) {
        printLog { "analyst scene completed count $anaCounterSceneSettle" }
        anaCounterSceneSettle++
        if (anaCounterSceneSettle > 0) {
            printLog { "analyst scene completed" }
            anaMarkSceneSettle()
        }
    }
    if (System.currentTimeMillis() - lastBlueDoorTs > 3000
        && System.currentTimeMillis() - lastBlacksmithTs > 3000) {
        anaCounterSceneSettle = 0
    }
}

private val cFWP1StartA1 by lazy { Block("疯王起点检测左inA1", selfInSmallMap.x - 34.pt, selfInSmallMap.y - 30.pt, 20.pt, 30.pt) }
private val cFWP1StartA2 by lazy { Block("疯王起点检测左inA2", selfInSmallMap.x - 34.pt, selfInSmallMap.y + 5.pt, 20.pt, 30.pt) }
private val cFWP1StartA3 by lazy { Block("疯王起点检测下inA3", selfInSmallMap.x - 10.pt, selfInSmallMap.y + 20.pt, 20.pt, 30.pt) }
private val cFWP1StartA4 by lazy { Block("疯王起点检测上outB1", selfInSmallMap.x - 20.pt, selfInSmallMap.y - 62.pt, 30.pt, 20.pt) }
private val cFWP1StartA5 by lazy { Block("疯王起点检测右outB2", selfInSmallMap.x + 45.pt, selfInSmallMap.y + 10.pt, 30.pt, 20.pt) }
private val cFWP1StartA6 by lazy { Block("疯王起点检测inA4", selfInSmallMap.x + 20.pt, selfInSmallMap.y - 40.pt, 16.pt, 16.pt) }
private val hitStartRoad by lazy { setOf(0xff363931.toInt().rgb(8),) }
private val hitStartPrimaryRoad by lazy { setOf(0xff444237.toInt().rgb(8),) }

fun analysisMapFWIsStartPoint(ss: Bitmap): Boolean {
    if (Analysis.hit(ss, cHMP1StartA8, hitStartFire, 4.pt, 0.16f, )) {
        return false // 毁灭误判成疯王了. 有火路驳回
    }

    if (System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && blockBlacksmith == null
        && blockBlueDoor != null
    ) {
        var hitPart = 0
        if (Analysis.hit(ss, cFWP1StartA1, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "fwP1"
        if (Analysis.hit(ss, cFWP1StartA2, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "fwP2"
        if (Analysis.hit(ss, cFWP1StartA3, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "fwP3"
        if (!Analysis.hit(ss, cFWP1StartA4, hitStartRoad, 4.pt, 0.1f, )) hitPart++ //  "fwP4"
        if (!Analysis.hit(ss, cFWP1StartA5, hitStartRoad, 4.pt, 0.1f, )) hitPart++ // , "fwP5"
        // hit [fwP6] 0.6 hitCount 15 total 25  // hit [fwP6] 0.16 hitCount 4 total 25
        if (Analysis.hit(ss, cFWP1StartA6, hitStartPrimaryRoad, 4.pt, 0.15f, )) hitPart++ // , "fwP6"
        if (hitPart >= 6) {
            printLog { "analystHM 节点.副本起点C" }
            anaLastSMapHMFeature1Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
    }

    val bbd = blockBlueDoor
    if (bbd != null && blockBlacksmith == null
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 16000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000) {
        val c1 = Block("P1入口检测a1", bbd.x + 40.pt, bbd.y - 120.pt, 40.pt, 20.pt)
        val c2 = Block("P1入口检测a2", bbd.x + 60.pt, bbd.y - 140.pt, 40.pt, 20.pt)
        val c3 = Block("P1入口检测a3", bbd.x + 80.pt, bbd.y - 160.pt, 40.pt, 20.pt)
        if (Analysis.hit(ss, c1, hitRoad, 5.pt, 0.24f) && // , "p1Enter1"  0.46666667 hitCount 21 total 45
            Analysis.hit(ss, c2, hitRoad, 5.pt, 0.24f) && // , "p1Enter2" 0.4888889 hitCount 22 total 45
            Analysis.hit(ss, c3, hitRoad, 5.pt, 0.24f)) { // , "p1Enter3"  0.37777779 hitCount 17 total 45
            printLog { "analystFW 节点.疯王路线是起点B" }
            anaLastSMapFWFeature9Ts = System.currentTimeMillis()
            // 下面2种方法也是的
            // [上,0s,0.82923055,c:42][下,1745973798s,c:0][左,1745973798s,c:0][右,0s,0.30929488,c:40]][Road,c:46]
            // [上,0s,0.7947792,c:54][下,1745973800s,c:0][左,1745973800s,c:0][右,0s,0.3275336,c:42]][Road,c:55]
            return true
        }
    }
    if ((blockBlueDoor == null || blockBlacksmith == null)
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000) {
        if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.75 .. 0.86
            && lastMapBottomP == null
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.21 .. 0.35
            && System.currentTimeMillis() - lastBlueDoorTs < 3000) {
            // [上,0s,0.79633856,c:52][下,70s,c:0][左,180s,c:0][右,0s,0.24908425,c:35]][Road,c:51]
            // [上,0s,0.8140402,c:47][下,1745974138s,c:0][左,1745974138s,c:0][右,0s,0.31081924,c:41]][Road,c:51]
            // [上,0s,0.82923055,c:42][下,1745973798s,c:0][左,1745973798s,c:0][右,0s,0.30929488,c:40]][Road,c:46]
            // [上,0s,0.7947792,c:54][下,1745973800s,c:0][左,1745973800s,c:0][右,0s,0.3275336,c:42]][Road,c:55]
            printLog { "analystFW 节点.疯王路线是起点A" }
            anaLastSMapFWFeature9Ts = System.currentTimeMillis()
            return true
        }
    }
    return false
}

private fun simpleAssertSceneCompleted(blueDoor: Block?, blacksmith: Block?): Boolean {
    if (blueDoor == null) return false
    if (blacksmith == null) return false
    val edge = 80.pt
    return blueDoor.right > smallMap.left + 120.pt // 结算的地图传送门在地图右边那边.左边的可能是P2起点
            && abs(blueDoor.x - blacksmith.x) < edge
            && abs(blueDoor.y - blacksmith.y) < edge
}


private fun angleSpecialAdjust(angle: Int): Int {
    if (System.currentTimeMillis() - xLastAtkTs < 300
        && System.currentTimeMillis() - lastEliteEnemyBossTs in 4000 .. 32000) {
        printLog { "angleSpecialAdjust atk stay by boss pass" }
        return (angle + 180) % 360
    }

    if (System.currentTimeMillis() - anaLastHasEnemyBossNameTs > 3000
        && System.currentTimeMillis() - lastEliteEnemyTs > 3000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 3000
        && System.currentTimeMillis() - xLastAtkTs < 600
        && System.currentTimeMillis() - sLastFeature30Ts > 2000) {
        printLog { "analystFW 回撤清理漏怪" }
        sLastFeature30Ts = System.currentTimeMillis()
        return (angle + 180) % 360
    }

    if (angle in 130 .. 330) {
        if (System.currentTimeMillis() - xLastAtkTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyTs > 5000
            && System.currentTimeMillis() - anaLastSMapFWFeature4Ts > 20000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000
            && System.currentTimeMillis() - xLastPetBlacksmithTs > 20000
            && System.currentTimeMillis() - xLastUnknownTs < 20000) {
            printLog { "analystFW angleSpecialAdjust $angle to 46" }
            return 46
        }
    }
    return angle
}